#include "common.hpp"
#include "Reactor.hpp"
#include"connection.hpp"
#include"Http.hpp"


void User(const char* agrv)
{
    std::cout<<"User should: "<< agrv <<" port"<<std::endl;
    exit(USER_ERR);
}

int main(int argc,char* argv[])
{
    if(argc != 2)
    {
        User(argv[0]);
    }
    uint16_t port = std::stoi(argv[1]);

    std::shared_ptr<Http> httpser = std::make_shared<Http>();
    std::shared_ptr<connection> liscon = std::make_shared<listener>(port);
    liscon->SetHandler([&httpser](int fd){
        std::shared_ptr<TcpSocket> fdptr = std::make_shared<TcpSocket>(fd);
        httpser->GetRequstHttp(fdptr);
    });
    std::shared_ptr<Reactor> serve = std::make_shared<Reactor>();

    serve->Addconnection(liscon);
    serve->start();
    return 0;
}